package com.prototype.view.background {
	import adobe.utils.CustomActions;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	/**
	 * ...
	 * @author Santiago.J.Elizalde
	 */
	public class BitmapScroller {
		
		private var xScroll:Number=0;
		
		private var _scrollSpeed:Number=1;
		private var _parallaxAmount:Number=1;
		
		private var data:BitmapData;
		private var scrollBuffer:BitmapData;
		public var display:Bitmap;
		
		public function BitmapScroller(data:BitmapData) {
			this.data = data;
			scrollBuffer = new BitmapData(data.width, data.height, true);
			display = new Bitmap(scrollBuffer);
		}
		
		public function scroll():void {
			
			xScroll += _scrollSpeed * _parallaxAmount;
			if (Math.abs(xScroll) >= data.width) {
				xScroll = 0;
			}
			scrollBuffer.lock();
			scrollBuffer.fillRect(scrollBuffer.rect, 0x00000000);
			scrollBuffer.copyPixels(data, new Rectangle(0, 0, data.width, data.height), new Point(data.width - Math.abs(xScroll), 0), null, null, true);
			scrollBuffer.copyPixels(data, new Rectangle(Math.abs(xScroll), 0, data.width, data.height), new Point(0, 0), null, null, true);
			scrollBuffer.unlock();
		}
		
		public function get scrollSpeed():Number {
			return _scrollSpeed;
		}
		public function set scrollSpeed(value:Number):void {
			_scrollSpeed = value;
		}
		
		public function get parallaxAmount():Number {
			return _parallaxAmount;
		}
		public function set parallaxAmount(value:Number):void {
			_parallaxAmount = value;
		}
	}
}